/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DA;

import Control.DBConnector;
import Entity.Interested;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 *
 * @author theInterloper
 */
public class interestedDA {

    public static void write(Interested interested) throws SQLException {
        
        int ID =            interested.getARTISTID();
        int CUSTOMERID =    interested.getCUSTOMERID();
        int ITEMID =        interested.getITEMID();
        int ARTISTID =      interested.getARTISTID();
        
        String insertInterested = "INSERT INTO interested (customer_customerID, item_itemID, item_artist_artistID) VALUES" 
                            + " ('"+ CUSTOMERID +"','"+ ITEMID +"','"+ ARTISTID  +"');";
        
        DBConnector dbconnect = new DBConnector();
        Connection connect = dbconnect.setUpConnection();
        Statement statement = connect.createStatement();
        statement.execute(insertInterested);
    }

    public static Interested read(int i) throws SQLException {
        String getByID = "select * from interested where interestedID = '" + i + "'";
        
        DBConnector dbconnect = new DBConnector();
        Connection connect = dbconnect.setUpConnection();
        Statement statement = connect.createStatement();
         
        ResultSet resultset = statement.executeQuery(getByID);
        
        Interested interested = new Interested();
        
        while (resultset.next()){
            interested.setID(resultset.getInt(1));
            interested.setCUSTOMERID(resultset.getInt(2));
            interested.setITEMID(resultset.getInt(3));
            interested.setARTISTID(resultset.getInt(4));
        }
       
        return interested;
    }
    
}
